<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>会员列表</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" media="all">
    <style>
        .orderList-container {
            padding: 20px;
        }

        td[data-field="imgUrl"] div,
        td[data-field="negativeImgUrl"] div {
            height: 120px;
        }

        .lay-form {
            padding: 20px;
        }

        .orderList-container {
            background-color: #fff;
        }

        .bar {
            display: flex;
            justify-content: flex-start;
            align-items: flex-end;
        }

        .searchInput {
            display: flex;
            align-items: flex-end;
        }

        .searchInput label {
            font-size: 12px;
        }

        .searchInput input {
            width: 200px;
        }

        .searchInput .layui-form-label {
            padding: 9px 0;
        }

        .bar .layui-form-label {
            padding: 0;
            padding-bottom: 4px;
            text-align: left;
        }

        .bar .layui-inline {
            margin-right: 20px;
        }

        .layui-table img {
            max-width: 200px;
            object-fit: contain;
        }

        .layui-table-cell {
            height: auto;
        }

        .layer-container {
            padding: 20px;
        }

        .layer-container ul {
            display: flex;
        }

        .layer-container ul li {
            border: 1px solid #efefef;
            flex: 1;
            padding: 30px;
            text-align: center;
        }

        .layer-container ul li p {
            line-height: 30px;
            color: #666;
        }

        .layer-container ul .flag {
            flex: 0 0 300px;
        }
    </style>
</head>

<body>
    <div class="orderList-container">
        <!-- 搜索 -->
        <div class="searchInput">
            <form class="layui-form" action="" lay-filter="resets">
                <div class="layui-inline">
                    <label class="layui-form-label">昵称：</label>
                    <input class="layui-input" name="name" placeholder="请输入微信昵称" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">手机号：</label>
                    <input type="text" class="layui-input" id="test1" name="userPhone" placeholder="请输入手机号"
                        autocomplete="off">
                </div>

                <!-- 筛选 -->
                <div class="layui-inline" id="status">
                    <label class="layui-form-label"
                        style="padding-left:10px; text-align:center; padding-right:0 ; width: 60px;">会员类型：</label>
                    <div class="layui-input-block" style="margin-left: 80px;">
                        <select name="level">
                            <option value="5">全部</option>
                            <option value="0">非会员</option>
                            <option value="1">VIP会员</option>
                            <option value="2">分销会员</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">注册时间：</label>
                    <input class="layui-input" name="createTime" id="test5" placeholder="注册日期" autocomplete="off">
                </div>

                <button class="layui-btn" data-type="reload" lay-submit="" lay-filter="searchForm">搜索</button>
                <button class="layui-btn layui-btn-primary" data-type="reload" lay-submit=""
                    lay-filter="reset">重置</button>
            </form>
        </div>
        <!-- <button class="layui-btn" id="exports" style="margin-top:20px;">导出全部订单</button> -->
        <table lay-filter="orderListTable" class="layui-hide" id="orderListTable"></table>

        <div id="sealId" style="display:none;padding: 10px;">
            <form class="layui-form" action="" lay-filter="example">
                <div style="color:red;padding: 18px 30px;">
                    *封号后用户不能提现、不能使用积分、不能分享、不能购买商品。分销订单状态的排队、升级、复投、获得收益都不收影响。请谨慎操作！</div>
                <div style="color:red;padding: 18px 30px;" id="last"></div>
                <div class="layui-form-item">
                    <label class="layui-form-label" id="fh_title">封号原因:</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" name="stopDes" class="fh-handle layui-textarea"></textarea>
                    </div>
                </div>
                <input type="hidden" name="id" />
                <input type="hidden" name="stop" class="stop-handle" />
                <div class="layui-form-item">
                    <button type="submit" style="margin-left: 124px;" class="layui-btn" lay-submit=""
                        lay-filter="submitAccount">立即提交</button>
                </div>
            </form>
        </div>
    </div>
    <div id="updateShareLayer" style="display:none;padding: 10px 50px;">
        <form class="layui-form" action="" lay-filter="exampleShare">
            <div class="layui-form-item">
                <label class="layui-form-label">推荐人手机号:</label>
                <div class="layui-input-block">
                    <input type="text" name="shareUserPhone" lay-verify="title"  autocomplete="off" placeholder="推荐人手机号" class="layui-input">
                </div>
            </div>
            <input type="hidden" name="id" class="userId"/>
            <div class="layui-form-item">
                <button type="submit" style="margin-left: 259px;" class="layui-btn" lay-submit="" lay-filter="shareSubmitAccount">立即提交</button>
            </div>
        </form>
    </div>
    <div id="updatePasswordLayer" style="display:none;padding: 10px 50px;">
        <form class="layui-form" action="" lay-filter="examplePassword">
            <div class="layui-form-item">
                <label class="layui-form-label">支付密码:</label>
                <div class="layui-input-block">
                    <input type="text" name="payPassWord" lay-verify="title"  autocomplete="off" placeholder="支付密码" class="layui-input">
                </div>
            </div>
            <input type="hidden" name="id" class="PasswordUserId"/>
            <div class="layui-form-item">
                <button type="submit" style="margin-left: 259px;" class="layui-btn" lay-submit="" lay-filter="passwordSubmitAccount">立即提交</button>
            </div>
        </form>
    </div>
</body>

<script type="text/html" id="authentication">
    {{# if( d.auth == 1 ) { }}
    <span style="color:blue;">已认证</span>
    {{# } }}
    {{# if( d.auth != 1 ) { }}
    <span style="color:blue;">未认证</span>
    {{# } }}
</script>

<script type="text/html" id="handle">
    {{# if( d.stop == 0 ) { }}
    <span style="color:red;" lay-event="seal">封号</span>
    {{# } }}
    {{# if( d.stop == 1 ) { }}
    <span style="color:red;" lay-event="alreadySeal">解封</span>
    {{# } }}
</script>

<script type="text/html" id="firstLevel">
    <span style="color:blue;" lay-event="firstDetail">{{d.levelOneOrderNum}}查看详情</span>
</script>
<script type="text/html" id="secondLevel">
    <span style="color:blue;" lay-event="secondDetail">{{d.levelTwoOrderNum}}查看详情</span>
</script>
<script type="text/html" id="handlePassword">
    <span style="color:blue;" lay-event="updatePassword">修改</span>
</script>
<script type="text/html" id="handleShare">
    <span style="color:blue;" lay-event="updateShare">修改</span>
</script>
<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.5.7/layui.all.min.js"></script>
<script src="../utils.js"></script>
<script>


    layui.use(['table', 'upload', 'form', 'jquery', "laydate"], function () {
        var table = layui.table,
            upload = layui.upload,
            form = layui.form,
            laydate = layui.laydate,
            $ = layui.jquery;

        table.render({
            elem: '#orderListTable',
            toolbar: "#barDemo",
            url: window.baseUrl + '/user/getUserList',
            headers: {
                Authorization: localStorage.token
            },
            method: 'post',
            contentType: 'application/json',
            response: {
                statusCode: 200 //规定成功的状态码，默认：0
            },
            cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            ,
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 200,
                    "count": res.data.recordsTotal, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            request: {
                pageName: 'start' //页码的参数名称，默认：page
                ,
                limitName: 'length' //每页数据量的参数名，默认：limit
            },
            cols: [
                [{
                    type: 'numbers'
                },
                {
                    type: 'checkbox'
                }, 
                {
                    field: 'name',
                    title: '昵称'
                }
                ,{
                    title: '头像',
                    width: 120,
                    templet: function (res) {
                        return res.userPhoto ? "<img class='viewImg' style='width:80px; height:80px;' src='" + res.userPhoto + "'/>" : "-"
                    }}
                , {
                    field: 'sex',
                    title: '性别',
                    templet: function (res) {
                        return res.sex == 1 ? "男" : res.sex == 0 ? "女" : "-"
                    }}
                , {
                    field: 'age',
                    title: '年龄',
                    templet: function (res) {
                        return res.age || "-"
                    }}
                , {
                    field: 'userPhone',
                    title: '手机号',
                    templet: function (res) {
                        return res.userPhone || "-"
                    }}
                , {
                field: 'level',
                title: '会员类型',
                templet: function (res) {
                    return res.level == 0 ? "非会员" : res.level == 1 ? "VIP会员" : res.level == 2 ? "分销会员" : res.level == 3 ? "分销会员" : res.level ? "分销会员" : '-';
                }}
                , {
                field: 'haveBouns',
                title: '是否享受提成',
                templet: function (res) {
                    return res.haveBouns == 0 ? "不享受提成" : res.haveBouns == 1 ? "享受提成" : '-'
                }}
                , {
                field: 'shareUserName',
                title: '推荐人',
                templet: function (res) {
                    return res.shareUserName || "-"
                }}
                , {
                    field: 'levelOneOrderNum',
                    title: '一级分销',
                    toolbar: '#firstLevel'
                }, {
                    field: 'levelTwoOrderNum',
                    title: '二级分销',
                    toolbar: '#secondLevel'
                }
                , {
                    field: 'benefitAll',
                    title: '总收益'
                }, {
                    field: 'integral',
                    title: '总积分'
                }, {
                    field: 'createTime',
                    title: '注册时间'
                }, {
                    field: 'createTime',
                    title: '实名认证',
                    toolbar: '#authentication'
                }, {
                    title: '操作',
                    toolbar: '#handle'
                }, {
                    title: '修改支付密码',
                    width: 130,
                    toolbar: '#handlePassword'
                }, {
                    title: '修改推荐人',
                    width: 130,
                    toolbar: '#handleShare'
                }
                ]
            ],
            page: true,
            done: function () {
                // 放大图片
                $(".viewImg").on("click", function () {
                    let url = $(this).attr("src");
                    layer.open({
                        type: 1,
                        title: false,
                        closeBtn: 0,
                        area: ['auto'],
                        skin: 'layui-layer-nobg', //没有背景色
                        shadeClose: true,
                        content: "<img src=" + url + " />"
                    });
                })

                laydate.render({
                    elem: '#test5'
                });
            }
        });

        table.on('tool(orderListTable)', function (obj) {

            var data = obj.data; //获得当前行数据
            console.log(data.stopTime)
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            if (layEvent === 'firstDetail') { //查看

                window.location.href = './vipDetail.html?id=' + data.id + '&shareLevel=1';
            } else if (layEvent === 'secondDetail') {
                window.location.href = './vipDetail.html?id=' + data.id + '&shareLevel=2';
            } else if (layEvent === 'updateShare') {
                layer.open({
                    type: 1,
                    title: '修改推荐人',
                    area: ['500px', '250px'],
                    shadeClose: false,
                    skin: 'yourclass',
                    content: $("#updateShareLayer")
                });
                form.val('exampleShare', {
                    shareUserPhone: ''
                });
                $(".userId").val(data.id);
            } else if (layEvent === 'updatePassword') {
                layer.open({
                    type: 1,
                    title: '修改支付密码',
                    area: ['500px', '250px'],
                    shadeClose: false,
                    skin: 'yourclass',
                    content: $("#updatePasswordLayer")
                });
                form.val('examplePassword', {
                    payPassWord: ''
                });
                $(".PasswordUserId").val(data.id);
            }else if (layEvent === 'alreadySeal') {
                layer.open({
                    type: 1,
                    title: '解除封号操作',
                    area: ['600px', '450px'],
                    shadeClose: false,
                    skin: 'yourclass',
                    content: $("#sealId")
                });
                $(".fh-handle").attr('name', 'openDes');
                $("#fh_title").html("解封原因");
                if (data.stopTime) {
                    $("#last").html("上次封号时间:" + data.stopTime + "   上次封号原因:" + data.stopDes);
                    //$("#lastDes").html("上次封号原因:"+data.stopDes);
                }
                form.val('example', {
                    openDes: "",
                    stop: 0,
                    id: data.id
                })

            } else if (layEvent === 'seal') {
                layer.open({
                    type: 1,
                    title: '封号操作',
                    area: ['600px', '450px'],
                    shadeClose: false,
                    skin: 'yourclass',
                    content: $("#sealId")
                });
                $(".fh-handle").attr('name', 'stopDes');
                $("#fh_title").html("封号原因");
                if (data.openTime) {
                    $("#last").html("上次解封时间:" + data.openTime + "   上次解封原因:" + data.openDes);
                    //$("#lastDes").html("上次解封原因:"+data.openDes);
                }
                form.val('example', {
                    stopDes: "",
                    stop: 1,
                    id: data.id
                })

            }
        });

        // 搜索
        form.on("submit(searchForm)", function (e) {

            if (e.field.createTime) {
                e.field.createTime = new Date(e.field.createTime).getTime();
            }

            for (let key in e.field) {
                if (!e.field[key]) {
                    delete e.field[key]
                }
            }

            table.reload('orderListTable', {
                page: {
                    start: 1 //重新从第 1 页开始
                },
                where: e.field
            });

            return false;
        })

        // 搜索
        form.on("submit(reset)", function (e) {

            table.reload('orderListTable', {
                page: {
                    start: 1 //重新从第 1 页开始
                },
                where: null
            });

            form.val("resets", {
                name: "",
                userPhone: "",
                createTime: ""
            });

            return false;
        })

        function layerOpen() {
            var checkStatus = table.checkStatus('orderListTable').data;
            layer.open({
                type: 1,
                title: "发短信",
                area: ['560px', '280px'], //宽高
                content: `
                        <form class="layui-form" action="" style="padding:20px;">
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">短信内容</label>
                                    <div class="layui-input-block">
                                    <textarea style="width: 300px;" name="msg" id="remark" placeholder="请输入短信内容" class="layui-textarea"></textarea>
                                    已选择：${checkStatus.length}人
                                </div>
                            </div>
                            <div class="layui-form-item" >
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                                </div>
                            </div>
                        </form>
                    `,
                success: function () {
                    form.render();
                }
            });
        }

        form.on("submit(demo1)", function (el) {

            var checkStatus = table.checkStatus('orderListTable'),
                data = checkStatus.data;

            if (!data.length) {
                layer.msg(`请选择用户在进行发送短信`)
                return false;
            }

            data.forEach((item, index) => {
                if (!item.userPhone) {
                    layer.msg(`第${(index + 1)}位用户没绑定手机号!`)
                    return false;
                }

                el.field.phone = item.userPhone;

                ajax({
                    path: "/user/sendMsg",
                    data: el.field,
                    success: function (res) {
                        if (index == (data.length - 1)) {
                            layer.closeAll();
                            layer.msg("短信发送完成");

                        }

                    }
                }, $)
            })

            return false;
        })

        // 编辑和删除
        table.on("toolbar(orderListTable)", function (data) {
            switch (data.event) {
                case "lookDetails":
                    layerOpen();
                    break;
            }
        })

        form.on("submit(submitAccount)", function (el) {
            ajax({
                path: "/user/updateUserStatus",
                data: el.field,
                success: function (res) {
                    console.log(res)
                    layer.closeAll();
                    layer.msg("修改成功")
                    table.reload("orderListTable");
                }
            }, $)
            form.val("example", {
                name: "",
                userPhone: "",
                createTime: ""
            });
            return false;
        })
        form.on("submit(shareSubmitAccount)", function (el) {
            ajax({
                path: "/user/uddateSharePhone?id="+el.field.id+"&shareUserPhone="+el.field.shareUserPhone,
                success: function (res) {
                    console.log(res)
                    layer.closeAll();
                    layer.msg("修改成功")
                    table.reload("orderListTable");
                }
            }, $)
            form.val("exampleShare", {
                shareUserPhone: ""
            });
            return false;
        })
        form.on("submit(passwordSubmitAccount)", function (el) {
            ajax({
                path: "/indexUser/updatePayPasswordForPc?userId="+el.field.id+"&payPassWord="+el.field.payPassWord,
                success: function (res) {
                    console.log(res)
                    layer.closeAll();
                    layer.msg("修改成功")
                    table.reload("orderListTable");
                }
            }, $)
            form.val("examplePassword", {
                payPassWord: ""
            });
            return false;
        })
    });
</script>

</html>